const url = "https://res.vmallres.com";
const shops = document.querySelector('.shop-body');
const discountArr = [];
getShopList()
// 获取过滤后的商品列表
function getShopList(){
    let shopList = resultList;
    shopList = shopList.filter((i)=>{
        let flag = true;
        for(let j=0;j<discountArr.length;j++){
            if(!i.promoLabels.includes(discountArr[j])){
                flag = false;
                break;
            }
        }
        return flag;
    })
    shops.innerHTML = ""
    for(let i=0;i<shopList.length;i++){
        var data = shopList[i];
        let msg = '';
        for(let n of data.promoLabels){
            msg+=`<div class="yh">${n}</div>`
        }
        shops.innerHTML+=`<li class="shop-item">
            <img src="${url}${data.photoPath}${data.photoName}" alt="">
            <div>
                ${msg}
            </div>
            <div>
                <div class="shop-name">
                    ${data.briefName}
                </div>
            </div>
            <div class="shop-text">
                dwadadawd|awdawdawdaw
            </div>
            <p>￥${data.price}</p>
        </li>`
    }
    shops.innerHTML+=`<li class=shop-item style="height:0px;padding:0px"></li>`;
    shops.innerHTML+=`<li class=shop-item style="height:0px;padding:0px"></li>`;
}
// 属性选择
const discount = document.querySelector('.discount');
const distUl = discount.querySelector('ul');

// 遍历属性选择
for(let j=0;j<distUl.children.length;j++){
    let new_node = distUl.children[j];
    new_node.addEventListener('click',function(){
        new_node.classList.toggle('active');
        let label = new_node.textContent.trim();
        if(new_node.classList.contains('active')){
            discountArr.push(label)
        }else{
            let index = discountArr.findIndex((i)=> i==label );
            discountArr.splice(index,1);
        }
        getShopList()
    })
}